package cn.liutao.common.utils;

import cn.liutao.auth.entity.po.User;
import cn.liutao.common.entity.LoginUser;
import cn.liutao.common.enums.CommonEnum;
import cn.liutao.common.exception.ForbiddenException;
import cn.liutao.common.exception.UnauthorizedException;
import lombok.Data;

@Data
public class AuthUtils {

    public static void isAdmin(){
        User loginUser = LoginUser.getLoginUser();
        if (loginUser==null){
            throw new UnauthorizedException("请重新登录");
        }
        if (loginUser.getIsAdmin().compareTo(CommonEnum.SYS_IS_ADMIN.getIntValue())!=0){
            throw new ForbiddenException("没有操作权限");
        }
    }
}
